import  numpy as np
import matplotlib.pyplot as plt
import demo60_data as ddata

x = np.array([
    [1,0.1],
    [0.1,1.1],
    [1,1],
    [-1,1],
    [-1,-0.1],
    [-0.1,-0.1],
])
y = np.array([
    [1,1,1,0,0,0]
]).T


x,y = ddata.exclusive()


np.random.seed(1)
w0 = np.random.random((2,8))
w1 = np.random.random((8,1))



for i in range(1000):
    l1_cache = np.matmul(x,w0)
    l1 = np.maximum(0,l1_cache)
    out_cache = np.matmul(l1,w1)
    out = np.maximum(0,out_cache)

    loss = y - out
    loss[out_cache < 0] = 0
    l1_delta = loss
    x_delta = l1_delta * w1.T
    x_delta[l1_cache < 0] = 0


    w1 = w1 + np.matmul(l1.T,l1_delta)
    w0 = w0 + np.matmul(x.T ,x_delta)

    #print(out,loss,l1_delta)
    if i%100==0:
        print(np.mean(np.abs( 1/(1+np.exp(-(y-out))))))

x_data = [v[0] for v in x]
y_data = [v[1] for v in x]

plt.scatter(x_data,y_data,c='#98FB98')
plt.show()
